// 表达式还原
import { traverse } from "@babel/core";
import { parse } from "@babel/parser";
import _generate from "@babel/generator";
import * as types from "@babel/types";
import fs from "fs";

const code = fs.readFileSync("code1.js", "utf-8");
let ast = parse(code);

traverse(ast, {
    "UnaryExpression|BinaryExpression|ConditionalExpression|CallExpression": (
        path
    ) => {
        const { confident, value } = path.evaluate();
        if (value === Infinity || value === -Infinity) return;
        confident && path.replaceWith(types.valueToNode(value));

    },
});
const { code: output } = _generate.default(ast);
console.log(output)

